<?php
include "../config.php";
include "../util/functions.php";

$GLOBALS['PATH_TO_HOME']="../";

session_start();

checkUserSession();

$mylink = mySqlOpen($mySQLserver, $mySQLuser, $mySQLpassword, $mySQLdefaultdb);

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    //    $tmp_file = $HTTP_POST_FILES['image']['name'];
//    $test_file = 'false';
//    if ($_FILES["image"]["tmp_name"]) {
//        $test_file = 'true';
//    }
//    $res = move_uploaded_file($_FILES["image"]["tmp_name"], 'upload/'.$_FILES["image"]["name"]);
//    $tmp_file = $_FILES['image']['name'];
    $portfolio = array(
        "id"            => $_POST['id'],
        "title"         => $_POST['title'],
        "date"          => webFormDateStrToArray($_POST['date']),
        "portfolio_image"    => $_FILES["image"]["tmp_name"],
    );

    //print_r($_FILES["image"]);

    $portfolio = updatePortfolio($portfolio);
} else {
    $portfolioId = $_REQUEST['portfolioId'];
    $portfolio = getPortfolio($portfolioId);
}

mySqlClose($mylink);



?>
<html>
<head>
<title>ООО "СитиМолПроект" - Современные технологии строительства и проэктирования- Главная</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta content="Современные технологии строительства и проектирования: новости, портфолио" name="description">
<meta content="строительство, проектирование, портфолио, новости" name="keywords">
<link href="../css/style.css?v=4" type="text/css" rel="stylesheet">
</head>
<body>
<center>

    <table width="1004" border="0">
        <tbody><tr>
            <td colspan="4">
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <table width="1004"><tbody><tr height="1"><td width="1004" bgcolor="#244aa7"></td></tr></tbody></table>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <?php
                include "../header.php";
                ?>
            </td>
        </tr>
        <tr>
            <td colspan="4">
                <?php
                include "admin_menu.php";
                ?>
            </td>
        </tr>
        <tr>
            <td style="height: 100%;" width="10">
            </td>
            <td width="900">
                <table class="main" border="0" width="100%" style="height:350px">
                    <tbody>
                    <tr>
                        <td>
                            <form action="edit_portfolio.php" method="post" enctype="multipart/form-data">
                            <input type="hidden" name="id" value="<?php print $portfolio['id']; ?>">
                            <table border="0" style="margin-top:20px" class="edit_news_tab">
                                <tr>
                                    <td style="width:150px;" align="right">название</td>
                                    <td align="left">
                                        <input name="title" maxlength="250" size="150" style="width:700px;" value="<?php print $portfolio['title']; ?>">
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">дата</td>
                                    <td align="left">
                                        <input name="date" value="<?php print arrayDateToWebFormDate($portfolio['date']); ?>">
                                        (Формат: ДД.ММ.ГГГГ)
                                    </td>
                                </tr>
                                <tr>
                                    <td align="right">картинка</td>
                                    <td align="left">
                            <?php   $image_file = 'upload/portfolios/img_'.$portfolio['id'].'.jpg';
                                    if (file_exists($GLOBALS['PATH_TO_HOME'].$image_file)) {  ?>
                                        <img src="<?php print $GLOBALS['PATH_TO_HOME'].$image_file.'?v='.$portfolio['version']; ?>" alt="" style="border-color:red" border="1">
                                        <br/>
                            <?php   }   ?>
                                        <input type="file" name="image">
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" align="right">
                                       <input type="submit" value="Save">
                                    </td>
                                </tr>
                            </table>
                        </form>
                        </td>
                    </tr>
                </tbody></table>
            </td>
            <td width="0">
            </td>

        </tr>
        <tr>
            <td colspan="4">
                <?php
                include "../footer.php";
                ?>
            </td>
        </tr>
    </tbody></table>




</center>

</body>
</html>